<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <FilterTable
      ref="table"
      :columns="columns"
      :dataSource="tableList"
      :isSelectColumn="false"
      height="auto"
      :onColumnsChange="columns => this.columns = columns"
    >

    </FilterTable>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>

    </div>
  </div>
</template>
<script>
import {getDetail,updatePlateApply,gettmFiAccountType,getLogList} from '@/api/omSale/PurchaseReturn/ReturnAudit/index.js';
import { dictionary } from '@/utils/dictMixin';
export default {
  data(){
    return{
      formList:this.createdFrom(),
      columns:this.createdTable(),
      tableList:[],
      issearch:false,
    }
  },
  components:{
  },
  created(){
    this.getDetail(this.rowData)
    this.getLogList(this.rowData.id)
  },
  props:['rowData'],
  mixins:[dictionary],
  methods:{
    createdFrom(){
      return [
        {
          type:'BREAK_SPACE',
          label:'退货申请'
        },
         {
          type: 'INPUT',
          label: '退货单号',
          fieldName: 'returnNo',
          placeholder: '请选择',
          disabled:true,

        },
        {
          type: 'INPUT',
          label: '经销商',
          fieldName: 'dealerName',
          placeholder: '请输入',
          disabled:true,
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun(1)}></el-button>
              </div>
            );
          },
        },
        {
          type: 'DATE',
          label: '申请日期',
          fieldName: 'applyDate',
          placeholder: '请输入',
          dateType:'exactdate',
          disabled:true
        },
        {
          type: 'SELECT',
          label: '退车原因',
          fieldName: 'returnReason',
          placeholder: '请输入',
          itemList:this.createDictList('6056'),
          disabled:true
        },
        {
          type: 'INPUT',
          label: '退货人',
          fieldName: 'applyPersonName',
          placeholder: '请输入',
          disabled:true,
        },

        {
          type: 'INPUT',
          label: '店内联系人',
          fieldName: 'linkMan',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入',
          disabled:true,
        },

        {
          type: 'INPUT',
          label: '销售订单号',
          fieldName: 'doNo',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '联系方式',
          fieldName: 'linkPhone',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '产品名称',
          fieldName: 'productName',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '原价格',
          fieldName: 'afterDiscountRebateAmount',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '原发票号',
          fieldName: 'goldenInvoiceNo',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '原税率',
          fieldName: 'rate',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '退车金额',
          fieldName: 'returnAmount',
          placeholder: '请输入',
          disabled:true,

        },
        {
          type: 'SELECT',
          label: '店端车辆状态',
          fieldName: 'vehicleStatus',
          placeholder: '请输入',
          disabled:true,
          itemList:this.createDictList('6040')
        },
        {
          type: 'INPUT',
          label: '原订单资金类型',
          fieldName: 'accountTypeName',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'SELECT',
          label: '退款账户',
          fieldName: 'returnAccount',
          placeholder: '请输入',
          disabled:true,
          itemList:[],
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },

        {
          type: 'TEXT_AREA',
          label: '退车原因说明',
          fieldName: 'returnReasonRemark',
          placeholder: '请输入',
          selfCols:3,
          disabled:true
        },
        {
          type: 'UPLOAD_FILE',
          label: '附件上传',
          fieldName: 'pos',
          placeholder: '请输入',
          initialValue:[],
          offsetRightCols:2,
          disabled:true,
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 1000,
            tipText: '最多上传1000个附件',
          },
        },
        {
          type: 'TEXT_AREA',
          label: '审核意见',
          fieldName: 'returnRemark',
          placeholder: '请输入',
          selfCols:3,
          disabled:true
        },
        {
          type:'BREAK_SPACE',
          label:'操作记录'
        },
      ]
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作状态',
          dataIndex: 'returnStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6055'),
          render: p => {
            return <span>{this.createDictText(p.row.returnStatus, '6055')}</span>;
          }
        },
        {
          title: '操作人员',
          dataIndex: 'createdBy',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '操作时间',
          dataIndex: 'createdAt',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '审核备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    seacherFun(){
      this.issearch=true;
    },
    changeHandle(val){
      this.saveData=val;
    },
    async getDetail(data){
      let res=await getDetail({id:data.id})
      if(res.data.pos&&res.data.pos.length>0){
        res.data.pos.map(x=>{
          x.name=x.fileName
          x.url=x.fileAddress
        })
      }

      for(let i in res.data){
        this.formList.map(x=>{
          if(x.fieldName==i){
            x.initialValue=res.data[i]
          }
        })
      }
      this.gettmFiAccountType();
    },
    async gettmFiAccountType(){
      let res=(await gettmFiAccountType({ doNo: this.formList.find(x=>x.fieldName=='doNo').initialValue })).data.map(x => ({ text: x.accountTypeName, value: x.id }));
      this.formList.find(x=>x.fieldName=='returnAccount').itemList=res;
    },
    async closeDrawer(type){
       if (type == 1) {
        this.$emit('close');
      }
    },
    async getLogList(id){
      const res1 = await getLogList({id:id});
      if (res1.resultCode == 200) {
        this.tableList = res1.data;
      }
    }
  }
}
</script>
